package com.cndw.kungfu.dao;

import java.util.List;

import com.cndw.dao.jade.Identity;
import com.cndw.dao.jade.annotation.DAO;
import com.cndw.dao.jade.annotation.SQL;
import com.cndw.dao.jade.annotation.SQLParam;
import com.cndw.kungfu.domain.Goods;

@DAO
public interface GoodsDao {
	/**
	 * 人物的背包的信息
	 */
	public static final String TABLE = " kf_player_goods ";

	public static final String FIELDS = " id,goodsId,level,playerId,useNO,position,binding,source,stackNum,storageType,storagePlace,createTime,hp,mp,attack,defense,hitR,dodgeR,luck,forgeLevel,holeCounts,gem,updateTime";

	/**
	 * 插入到背包
	 * 
	 * @param player
	 * @return
	 */
	@SQL("INSERT INTO "
			+ TABLE
			+ " ("
			+ FIELDS
			+ ") VALUES(0,:p.goodsId,:p.level,:p.playerId,:p.useNo,:p.position,:p.binding,:p.source,:p.stackNum,:p.storageType,:p.storagePlace,:p.createTime,:p.hp,:p.mp,:p.attack,:p.defense,:p.hitR,:p.dodgeR,:p.luck,:p.forgeLevel,:p.holeCounts,:p.gem,:p.updateTime)")
	public Identity insert(@SQLParam("p") Goods playerGoods);

	/**
	 * 批量更新装备
	 * 
	 * @param goods
	 * @return
	 */

	@SQL("Update "
			+ TABLE
			+ " set goodsId=:p.goodsId,level=:p.level,playerId=:p.playerId,useNO=:p.useNo,position=:p.position,binding=:p.binding,source=:p.source,stackNum=:p.stackNum,storageType=:p.storageType,storagePlace=:p.storagePlace,createTime=:p.createTime,hp=:p.hp,mp=:p.mp,attack=:p.attack,defense=:p.defense,hitR=:p.hitR,dodgeR=:p.dodgeR,luck=:p.luck,forgeLevel=:p.forgeLevel,holeCounts=:p.holeCounts,gem=:p.gem,updateTime=:p.updateTime where Id=:p.id ")
	public int saveDB(@SQLParam("p") Goods goods);

	/**
	 * 查询背包记录
	 * 
	 * @param playerId
	 * @return
	 */
	@SQL("select " + FIELDS + " from " + TABLE + " where playerId=:pId order by updateTime,id ")
	public List<Goods> getByPlayer(@SQLParam("pId") long playerId);

	/**
	 * 删除某个道具
	 * 
	 * @param playerId
	 * @param goodsId
	 * @return
	 */
	@SQL("delete from " + TABLE + " where playerId=:pId and goodsId=:gId ")
	public int deleteByGoodsId(@SQLParam("pId") long playerId, @SQLParam("gId") int goodsId);

	@SQL("delete from " + TABLE + " where Id=:id")
	public int deleteById(@SQLParam("pId") long playerId, @SQLParam("id") long id);

	@SQL("select " + FIELDS + " from " + TABLE + " where playerId=:pId and id=:id")
	public Goods selectOne(@SQLParam("pId") long playerId,@SQLParam("id") long id);
	
}
